import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
// @ts-ignore
import QRCode from 'qrcode';
import {environment} from '../../../../../../../environments/environment';

interface DeviceInfo {
  type: string; // 机型
  color: string; // 颜色
  memory: string; // 内存
  version: string; // 版本
  network: string; // 网络
  serial: string; // 编号
  serialNumber: string; // 编号
  imei: string; // IMEI
  chargeCount: string; // 充电次数
  batteryHealth: string; // 电池健康
}

@Component({
  selector: 'app-print-device-info',
  templateUrl: './print-device-info.component.html',
  styleUrls: ['./print-device-info.component.scss']
})
export class PrintDeviceInfoComponent implements OnInit, OnChanges {
  @Input() deviceInfo: DeviceInfo | undefined;

  constructor() {
  }

  ngOnInit(): void {
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (this.deviceInfo?.serial) {
      QRCode.toString(environment.VALUE_KEY_URL_PRINT + this.deviceInfo?.serial, {
        type: 'terminal',
        margin: 0
      }, (err: any, url: any) => {
        // @ts-ignore
        document.getElementById('deviceQrcode').innerHTML = url;
      });
    }
  }

}
